package cn.gov.msa.service.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import cn.gov.msa.service.ApplyService;
import cn.gov.msa.service.TaskSchedulingService;
import cn.gov.msa.util.RedisSynLock;

@Service("scheduleServiceImpl")
public class ScheduleServiceImpl {
	
	Logger logger = Logger.getLogger(ScheduleServiceImpl.class);
	
	@Autowired
	ApplyService applyService;
	
	public void scheduleTest() {
        logger.info("*********任务每10秒执行一次进入测试*********");
        
        try {
//            applyService.saveAmanuensisByTask();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Autowired
	TaskSchedulingService taskSchedulingService;

	/**
	 * 监督检查
	 */
	// 0 0/30 8-17 * * ?
//	@Scheduled(cron="${cron.inspect}")
	public void scheduleInspect() {
        logger.info("监督检查*********每天8-18时任务每30分钟执行一次*********");
        try {
        	taskSchedulingService.superInspecByTask();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 发送短信
	 */
	// 0/10 * 8-17 * * ?
	@Scheduled(cron="0 0/1 8-17 * * ?")
	@RedisSynLock(synKey = "SendMessage", expire = 40*1000)
	public void scheduleSendMessage() {
		try {
			taskSchedulingService.sendMessageByTask();

		} catch (Exception e) {
			logger.error("短信发送定时任务出错", e);
		}
	}
	
	/**
	 * 预约提醒
	 */
	// 0 0 6 * * ?
//	@Scheduled(cron="${cron.reserve}")
	public void scheduleReserve() {
		logger.info("预约提醒*********任务每天6点执行一次*********");
		try {
			taskSchedulingService.remindReserve();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 电子监察提醒
	 */
	// 0 0 8-18 * * ?
//	@Scheduled(cron="${cron.supervise}")
	public void scheduleSupervise() {
		logger.info("电子监察提醒*********每天8-18时任务小时执行一次*********");
		try {
			taskSchedulingService.remindLimitSupervise();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
